package cn.zzp.basic.interceptor.config;

import cn.zzp.basic.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author Administrator
 * @description: 加载拦截器配置【相当于以前的xml配置文件】
 * @date 2022/7/30 17:26
 */
@Configuration
public class MyWebConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;

    // 添加拦截器配置
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")  // 添加拦截路径
                // 放行登录请求
                .excludePathPatterns("/login/**")
                // 放行注册请求
                .excludePathPatterns("/user/phoneRegister","/verifyCode/**","/shop/settlement","/fastdfs/**")
                //放行swagger
                .excludePathPatterns("/swagger-resources/**", "/webjars/**",
                        "/v2/**", "/swagger-ui.html/**");
                // 如果有邮箱注册需要把邮箱注册添加到放行资源中
    }
}
